From 05db86c11aabe0e652fa9467ddf0d69baf35219e Mon Sep 17 00:00:00 2001 From: robertlipe Date: Tue, 31 Dec 2013 22:06:01 +0000 Subject: [PATCH] More fixes. --- gpsbabel/g7towin.cc | 17 ++++++----------- gpsbabel/gopal.cc | 2 +- gpsbabel/gtm.cc | 30 +++++++++++++----------------- gpsbabel/hiketech.cc | 28 ++-------------------------- gpsbabel/holux.cc | 4 ++-- gpsbabel/ik3d.cc | 31 ++++++++----------------------- 6 files changed, 32 insertions(+), 80 deletions(-) diff --git a/gpsbabel/g7towin.cc b/gpsbabel/g7towin.cc index fa25e7f90..67c22ab27 100644 --- a/gpsbabel/g7towin.cc +++ b/gpsbabel/g7towin.cc @@ -109,7 +109,7 @@ parse_line(char* buff, int index, const char* delimiter, waypoint* wpt) break; case WAYPT__OFS + 1: - wpt->description = xstrdup(cin); + wpt->description = (cin); break; case WAYPT__OFS + 2: @@ -129,14 +129,7 @@ parse_line(char* buff, int index, const char* delimiter, waypoint* wpt) case WPT_cA_OFS + 1: case WPT_c1_OFS + 1: -#if NEW_STRINGS wpt->shortname = cin; -#else - if (wpt->shortname) { - xfree(wpt->shortname); - } - wpt->shortname = xstrdup(cin); -#endif break; case WPT_cA_OFS + 4: @@ -298,7 +291,9 @@ parse_waypt(char* buff) cin--; } if (cin >= buff) { - wpt->shortname = xstrndup(buff, cin - buff + 1); + char*s = xstrndup(buff, cin - buff + 1); + wpt->shortname = s; + xfree(s); } if (gardown) { @@ -549,7 +544,7 @@ data_read(void) s = strrchr(cdata, ','); if (s) { *s = '\0'; - head->rte_name = xstrdup(cdata); + head->rte_name = cdata; } } } @@ -562,7 +557,7 @@ data_read(void) head = route_head_alloc(); cdata += 3; /*skip route number */ if (*cdata) { - head->rte_name = xstrdup(cdata); + head->rte_name = cdata; } route_add_head(head); break; diff --git a/gpsbabel/gopal.cc b/gpsbabel/gopal.cc index d13a0570e..72106488c 100644 --- a/gpsbabel/gopal.cc +++ b/gpsbabel/gopal.cc @@ -184,7 +184,7 @@ gopal_read(void) strftime(routename,sizeof(routename),"Tracklog %c",gmtime(&tx)); route = route_head_alloc(); - route->rte_name=xstrdup(routename); + route->rte_name = routename; route_add_head(route); line=0; diff --git a/gpsbabel/gtm.cc b/gpsbabel/gtm.cc index 449f8a097..f98ddd1fc 100644 --- a/gpsbabel/gtm.cc +++ b/gpsbabel/gtm.cc @@ -72,7 +72,7 @@ fread_bool(gbfile* fd) #define fread_single(a) gbfgetflt(a) #define fread_double(a) gbfgetdbl(a) -static char* +QString fread_string(gbfile* fd) { char* val; @@ -88,20 +88,18 @@ fread_string(gbfile* fd) len--; } val[len] = 0; - return val; + QString v(val); + xfree(val); + return v; } static void fread_string_discard(gbfile* fd) { - char* temp = fread_string(fd); - - if (temp != NULL) { - xfree(temp); - } + fread_string(fd); } -static char* +QString fread_fixedstring(gbfile* fd, int len) { char* val = (char*) xmalloc(len+1); @@ -111,7 +109,10 @@ fread_fixedstring(gbfile* fd, int len) len--; } val[len] = 0; - return val; + QString v(val); + xfree(val); + + return v; } /* Write functions, according to specification. */ @@ -394,20 +395,18 @@ static void gtm_rd_init(const char* fname) { int version; - char* name; file_in = gbfopen_le(fname, "rb", MYNAME); version = fread_integer(file_in); - name = fread_fixedstring(file_in, 10); + QString name = fread_fixedstring(file_in, 10); if (version == -29921) { fatal(MYNAME ": Uncompress the file first\n"); } - if (strcmp(name, "TrackMaker") != 0) { + if (name != "TrackMaker") { fatal(MYNAME ": Invalid file format\n"); } if (version != 211) { fatal(MYNAME ": Invalid format version\n"); } - xfree(name); /* Header */ fread_discard(file_in, 15); @@ -515,7 +514,6 @@ gtm_read(void) route_head* rte_head = NULL; waypoint* wpt; int real_tr_count = 0; - char* route_name; unsigned int icon; int i; @@ -603,7 +601,7 @@ gtm_read(void) convert_datum(&wpt->latitude, &wpt->longitude); wpt->shortname = fread_fixedstring(file_in, 10); wpt->description = fread_string(file_in); - route_name = fread_string(file_in); + QString route_name = fread_string(file_in); icon = fread_integer(file_in); if (icon < sizeof(icon_descr)/sizeof(char*)) { wpt->icon_descr = icon_descr[icon]; @@ -621,8 +619,6 @@ gtm_read(void) rte_head = route_head_alloc(); rte_head->rte_name = route_name; route_add_head(rte_head); - } else { - xfree(route_name); } route_add_wpt(rte_head, wpt); } diff --git a/gpsbabel/hiketech.cc b/gpsbabel/hiketech.cc index 1b14f65d0..99bb7bb57 100644 --- a/gpsbabel/hiketech.cc +++ b/gpsbabel/hiketech.cc @@ -200,7 +200,7 @@ void ht_wpt_s(xg_string args, const QXmlStreamAttributes* unused) static void ht_ident(xg_string args, const QXmlStreamAttributes* unused) { - wpt_tmp->shortname = xstrdup(args); + wpt_tmp->shortname = args; } static @@ -212,31 +212,19 @@ void ht_sym(xg_string args, const QXmlStreamAttributes* unused) static void ht_lat(xg_string args, const QXmlStreamAttributes* unused) { -#if NEW_STRINGS wpt_tmp->latitude = args.toDouble(); -#else - wpt_tmp->latitude = atof(args); -#endif } static void ht_long(xg_string args, const QXmlStreamAttributes* unused) { -#if NEW_STRINGS wpt_tmp->longitude = args.toDouble(); -#else - wpt_tmp->longitude = atof(args); -#endif } static void ht_alt(xg_string args, const QXmlStreamAttributes* unused) { -#if NEW_STRINGS wpt_tmp->altitude = args.toDouble(); -#else - wpt_tmp->altitude = atof(args); -#endif } static @@ -262,7 +250,7 @@ void ht_trk_e(xg_string args, const QXmlStreamAttributes* unused) static void ht_trk_ident(xg_string args, const QXmlStreamAttributes* unused) { - trk_head->rte_name = xstrdup(args); + trk_head->rte_name = args; } static @@ -299,31 +287,19 @@ void ht_trk_utc(xg_string args, const QXmlStreamAttributes* unused) static void ht_trk_lat(xg_string args, const QXmlStreamAttributes* unused) { -#if NEW_STRINGS wpt_tmp->latitude = args.toDouble(); -#else - wpt_tmp->latitude = atof(args); -#endif } static void ht_trk_long(xg_string args, const QXmlStreamAttributes* unused) { -#if NEW_STRINGS wpt_tmp->longitude = args.toDouble(); -#else - wpt_tmp->longitude = atof(args); -#endif } static void ht_trk_alt(xg_string args, const QXmlStreamAttributes* unused) { -#if NEW_STRINGS wpt_tmp->altitude = args.toDouble(); -#else - wpt_tmp->altitude = atof(args); -#endif } diff --git a/gpsbabel/holux.cc b/gpsbabel/holux.cc index 814106706..2ba4a5862 100644 --- a/gpsbabel/holux.cc +++ b/gpsbabel/holux.cc @@ -117,8 +117,8 @@ static void data_read(void) strncpy(desc,pWptHxTmp->comment,sizeof(pWptHxTmp->comment)); desc[sizeof(pWptHxTmp->comment)]=0; - wpt_tmp->shortname = xstrdup(name); - wpt_tmp->description = xstrdup(desc); + wpt_tmp->shortname = name; + wpt_tmp->description = desc; wpt_tmp->SetCreationTime(0); if (pWptHxTmp->date.year) { diff --git a/gpsbabel/ik3d.cc b/gpsbabel/ik3d.cc index 32f1cf81e..65a5d67e8 100644 --- a/gpsbabel/ik3d.cc +++ b/gpsbabel/ik3d.cc @@ -31,7 +31,7 @@ static arglist_t ikt_args[] = { #define MYNAME "ikt" -static char* name, *text; +static QString name, text; static route_head* track; static waypoint* waypt; @@ -59,22 +59,14 @@ ikt_object_end(void) if (track) { track->rte_name = name; track_add_head(track); - name = NULL; } else if (waypt) { waypt->shortname = name; waypt->description = text; waypt_add(waypt); - name = NULL; - text = NULL; - } - if (name) { - xfree(name); - name = NULL; - } - if (text) { - xfree(text); - text = NULL; } + + name = QString(); + text = QString(); track = NULL; waypt = NULL; } @@ -102,13 +94,13 @@ iktobj_trkpt(xg_string args, const QXmlStreamAttributes* attrv) static void iktobj_name(xg_string args, const QXmlStreamAttributes* unused) { - name = xstrdup(args); + name = args; } static void iktobj_text(xg_string args, const QXmlStreamAttributes* unused) { - text = xstrdup(args); + text = args; } static void @@ -138,8 +130,8 @@ ikt_rd_init(const char* fname) track = NULL; waypt = NULL; - name = NULL; - text = NULL; + name = QString(); + text = QString(); } static void @@ -152,13 +144,6 @@ static void ikt_rd_deinit(void) { ikt_object_end(); - if (name) { - xfree(name); - } - if (text) { - xfree(text); - } - xml_deinit(); } -- 2.30.2